package com.Controller;

import com.Service.OrdersService;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/UserOrdersAdd")
    public R UserOrdersAdd(
            @RequestParam("user_tel") String userTel,
            @RequestParam("subject1Name") String subject1Name,
            @RequestParam("subject2Name") String subject2Name,
            @RequestParam("subject3Name") String subject3Name,
            @RequestParam("textarea") String textarea,
            @RequestParam("province") String province,
            @RequestParam("city") String city,
            @RequestParam("area") String area,
            @RequestParam("addressIp") String addressIp,
            @RequestParam("longitude") String longitude,
            @RequestParam("latitude") String latitude,
            @RequestPart("ImageList") MultipartFile[] imageList) {

        return new R(ordersService.UserOrdersAdd(userTel, subject1Name, subject2Name, subject3Name, textarea,
                province, city, area, addressIp, longitude, latitude, imageList) > 0);
    }

    @PostMapping("/UserDelOrder")
    public R UserDelOrder(@RequestBody Map<String, String> Map_All) {
        String OrderUuid = Map_All.get("orderUuid");
        return new R(ordersService.UserDelOrder(OrderUuid) > 0);
    }


    @PostMapping("/findEngineerOrders0")
    public R findEngineerOrders0(@RequestBody Map<String, String> Map_All) {
        String engineerTel = Map_All.get("tel");
        return new R(true, ordersService.findEngineerOrders0(engineerTel));
    }
    @PostMapping("/findEngineerOrders1")
    public R findEngineerOrders1(@RequestBody Map<String, String> Map_All) {
        String engineerTel = Map_All.get("tel");
        return new R(true, ordersService.findEngineerOrders1(engineerTel));
    }
    @PostMapping("/findEngineerOrders2")
    public R findEngineerOrders2(@RequestBody Map<String, String> Map_All) {
        String engineerTel = Map_All.get("tel");
        return new R(true, ordersService.findEngineerOrders2(engineerTel));
    }
    @PostMapping("/findEngineerOrders3")
    public R findEngineerOrders3(@RequestBody Map<String, String> Map_All) {
        String engineerTel = Map_All.get("tel");
        return new R(true, ordersService.findEngineerOrders3(engineerTel));
    }
    @PostMapping("/findEngineerOrders4")
    public R findEngineerOrders4(@RequestBody Map<String, String> Map_All) {
        String engineerTel = Map_All.get("tel");
        return new R(true, ordersService.findEngineerOrders4(engineerTel));
    }

    @PostMapping("/findUserOrders0")
    public R findUserOrders0(@RequestBody Map<String, String> Map_All) {
        String userTel = Map_All.get("tel");
        return new R(true, ordersService.findUserOrders0(userTel));
    }
    @PostMapping("/findUserOrders1")
    public R findUserOrders1(@RequestBody Map<String, String> Map_All) {
        String userTel = Map_All.get("tel");
        return new R(true, ordersService.findUserOrders1(userTel));
    }
    @PostMapping("/findUserOrders2")
    public R findUserOrders2(@RequestBody Map<String, String> Map_All) {
        String userTel = Map_All.get("tel");
        return new R(true, ordersService.findUserOrders2(userTel));
    }
    @PostMapping("/findUserOrders3")
    public R findUserOrders3(@RequestBody Map<String, String> Map_All) {
        String userTel = Map_All.get("tel");
        return new R(true, ordersService.findUserOrders3(userTel));
    }
    @PostMapping("/findUserOrders4")
    public R findUserOrders4(@RequestBody Map<String, String> Map_All) {
        String userTel = Map_All.get("tel");
        return new R(true, ordersService.findUserOrders4(userTel));
    }

    @PostMapping("/UserFindEngineerOrder")
    public R selectEngineersByOrderUuidAndState(@RequestBody Map<String, String> Map_All) {
        String uuid = Map_All.get("orderUuid");
        System.out.println(uuid);
        return new R(true, ordersService.selectEngineersByOrderUuidAndState(uuid));
    }
    @PostMapping("/selectOrderEngineer")
    public R selectOrderEngineer(@RequestBody Map<String, String> Map_All) {
        String uuid = Map_All.get("orderUuid");
        System.out.println(uuid);
        return new R(true, ordersService.selectOrderEngineer(uuid));
    }

    @PostMapping("/UserOrderAddEngineer")
    public R UserOrderAddEngineer(@RequestBody Map<String, String> Map_All) {
        String uuid = Map_All.get("orderUuid");
        String engineerTel = Map_All.get("engineerTel");
        return new R(ordersService.UserOrderAddEngineer(uuid,engineerTel)>0);
    }
    @PostMapping("/OrderConfirm")
    public R OrderConfirm(@RequestBody Map<String, String> Map_All) {
        String uuid = Map_All.get("orderUuid");
        return new R(ordersService.OrderConfirm(uuid)>0);
    }
    @PostMapping("/UserOrderConfirm")
    public R UserOrderConfirm(@RequestBody Map<String, String> Map_All) {
        String uuid = Map_All.get("orderUuid");
        return new R(ordersService.UserOrderConfirm(uuid)>0);
    }


}